<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .box{
            margin: 50px;
        }
        .box .title{
            font-weight: bold;
            line-height: 80px;
            text-align: center;
        }
        .box .block{
            margin: 30px 0;
        }
        .box .block input{
            height: 40px;
            padding-left: 20px;
            border: 1px solid #ccc;
            border-radius: 10px;
            width: 100%;
            outline: none;
            box-sizing: border-box;
        }
        .t1{
            color: rgb(75, 75, 255);
            margin-left: 450px;
            font-size: 14px;
        }
        .box .block input2{
            background-color: rgb(92, 92, 252);
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="title">登录</div>
        <div class="block">
            <input type="text" placeholder="请输入用户名">
        </div>
        <div class="block">
            <input type="password" placeholder="请输入密码">
            <p class="t1">忘记密码</p>
        </div>
        <div class="block">
            <input type="button" value="登录">
        </div>
    </div>
</body>
</html>
<script src="./封装函数.js"></script>
<script>
    var inpts=document.querySelectorAll('.box .block input')
    inpts[2].onclick=function(){
        if(inpts[0].value && inpts[1].value){
            if(/^\d{4}$/.test(inpts[1].value)){
                ajax('get','https://yantianfeng.com/api/login',{username:inpts[0].value,password:inpts[1].value},function(data){
                    // console.log(data);
                    if(data.code==200){
                        alert("登陆成功");
                    }else{
                        alert("登录失败");
                    }
                })
            }else{
                alert('请输入正确的手机号/密码')
            }
        }else{
            alert('用户名/密码不能为空')
        }
        
    }
</script>